﻿#include "DemoApp.h"
#include "bridge.h"
#include "bridge_for_render.h"
#include <stdio.h>
#include<time.h>  
#include "DetourCommon.h"
using namespace std;
int main(int argc, char** argv)
{
	Race* race = AllocRaceLogic();
	if (!race->load_geom("../../../res/recast_demo_28"))
		return -1;
	if (!race->load_navmesh_from_file("../../../res/recast_demo_navmesh_28.bytes"))
		return -1;

	if (!race->initCrowd(40, fixed64::_0_50 + fixed64::_0_10))
		return -1;

	fixed64 s[3];
	s[0] = (FPRaw)(-6.623 * 65536.0);
	s[1] = (FPRaw)(0.33 * 65536.0);
	s[2] = (FPRaw)(8.173 * 65536.0);
	race->addAgent(s);

	////printf("%d, %d, %d \n", p[0], p[1], p[2]);

	//fixed64 e[3];

	//e[0] = (FPRaw)(-12.12*65536);
	//e[1] = (FPRaw)(0.24 * 65536);
	//e[2] = (FPRaw)(5.94 * 65536);
	////for (int i =0; i < 100; ++i)
	////{
	////	fixed64 p[3];
	////	race->randomPos(p);
	////	race->addAgent(p);
	////	printf("%d, %d, %d \n", p[0], p[1], p[2]);
	////}
	fixed64 vel[3];
	vel[0] = fixed64::_1;
	vel[1] = fixed64::ZERO;
	vel[2] = fixed64::ZERO;

	race->agentMoveVelocity(0, vel);
	fixed64 pos[3];
	//获取系统时间  
	time_t start_time = time(NULL);
	while (true)
	{
		time_t now_time = time(NULL);
		if (now_time - start_time < 1)
		{
			continue;
		}
		start_time = now_time;
		race->update(fixed64::_0_05);
		race->getAgentPos(0, pos);
		printf("%.2f, %.2f, %.2f \n", (float)pos[0], (float)pos[1], (float)pos[2]);
		//race->setAgentPos(0, e);
	}
	//bool res = dtPointInPolygon(0, 0, 0);
	return 0;
}